
import { BaseState, StateMachine } from "../base/fsm";
import EventManager from "../manager/EventManager";
import Unit from "./Unit";

/**
 * 技能事件
 */
export const SkillEvent = {
    /**准备 */
    Prepare: 'Prepare',
    /**施放 */
    Spell: 'Spell',
    /**CD */
    CD: 'CD',
}
/**
 * 技能状态
 */
export class SkillState extends BaseState<Unit>{
    fsm: Skill = null;
    constructor(fsm: Skill, name: string) {
        super();
        this.fsm = fsm;
        this.name = name;
    }
    onEnter() {
    }
    onUpdate() {
    }
    onQuit() {
    }
}
/**
 * 准备状态
 */
export class PrepareState extends SkillState { }
/**
 * 施放状态
 */
export class SpellState extends SkillState { }
/**
 * CD间隔状态
 */
export class CDState extends SkillState { }
/**
 * 技能状态机
 */
export abstract class Skill extends StateMachine<Unit>{
    unit: Unit = null;
    skillData = null;
    cd: number;
    defaultState: SkillState = null;
    public constructor(skillData) {
        super();
        this.skillData = skillData;
        this.init();
    }
    /**
     * 初始化方法
     * 子类必须实现重写
     */
    public abstract init();

    /**
     * 检测是否可以施放技能
     * 子类必须实现重写
     */
    public abstract checkCanSpell(): boolean;

    /**
     * 发送事件
     */
    public sendEvent(eventType: string, ...arg) {
        EventManager.instance.emit(eventType, ...arg);
    }
}
